package ws.very.util.dingtalk.api

import com.dingtalk.open.client.ServiceFactory
import com.dingtalk.open.client.api.service.corp.JsapiService

import scala.concurrent.{ExecutionContext, Future}

private[dingtalk] object JsApiServiceHelper {
  val serviceFactory: ServiceFactory = ServiceFactory.getInstance
  val jsapiService = serviceFactory.getOpenService(classOf[JsapiService])

  def getJsapiTicket(accessToken: S, typz: S)(implicit executor: ExecutionContext) = Future {
    val ticket = jsapiService.getJsapiTicket(accessToken, typz)
    (ticket.getTicket, ticket.getExpires_in * 1000 + now.mill)
  }
}
